package com.inlife.spider.Util;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexUtil {
	
	public String getMatch(String html,String pattern)
	{
		String temp = null;
        Pattern p = Pattern.compile(pattern);

        Matcher m = p.matcher(html);

        while(m.find()) {
        	temp = m.group();
        }

		return temp;
	}
	
	public boolean isMatch(String html,String pattern)
	{
		String temp = null;
        Pattern p = Pattern.compile(pattern);

        Matcher m = p.matcher(html);

        if(m.find()) {
        	return true;
        }

		return false;
	}
	public List getMatchs(String html,String pattern)
	{
		List links = new ArrayList();
		
        Pattern p = Pattern.compile(pattern);

        Matcher m = p.matcher(html);

        while (m.find()) {
        	String tt = m.group();
        	if(!links.contains(tt))
        	{
        		links.add(tt);
        	}
        }

		return links;
	}
}
